/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2024-01-13 14:58:04
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-01-13 21:24:17
 * @FilePath: \My-bolg\server\middleware\friend.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%A
 */
/* 校验文章上传的参数 */
const Response = require("../util/respanse.js")

const everfyaddprams = (req, res, next) => {
    let fleg
    let { friend_name, friend_url, friend_corver, friend_sign } = req.body
    let len = Object.keys(req.body).length
    if (!friend_name || !friend_url || !friend_corver || !friend_sign || !len) {
        fleg = true
        Response.errorresponse(res, {
            code: 400,
            msg: "参数不完整",
        })
    }
    if (len < 4 || len > 5) {
        fleg = true
        Response.errorresponse(res, {
            code: 400,
            msg: "参数个数不完整",
        })
    }
    if (!fleg) {
        next()
    }

}
const everfygetprams = (req, res, next) => {
    let fleg
    let { pageSize, page } = req.query
    if (!pageSize || !page) {
        fleg = true
        Response.errorresponse(res, {
            code: 400,
            msg: "参数不完整",
        })
    }
    if (!fleg) {
        next()
    }
}
const everfysercgprams = (req, res, next) => {
    let { keyword, page, pageSize } = req.body
    let fleg
    if (!keyword || !page || !pageSize) {
        fleg = true
        Response.errorresponse(res, {
            code: 400,
            msg: "参数不完整",
        })
    }
    if (!fleg) {
        next()
    }
}
const confirmprams = (req,res,next)=>{
    let fleg
    try {
        let {deleteidlist} = req.body
        if(!deleteidlist || !Array.isArray(deleteidlist)){
            fleg = true
            Response.errorresponse(res, {
                code: 400,
                msg: "参数不完整",
            })
        }
        if (!fleg) {
            next()
        }
    } catch (error) {
        console.log(error);
        
    }
}   
module.exports = {
    everfyaddprams,
    everfygetprams,
    everfysercgprams,
    confirmprams
}